package com.example.kotlindemo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val textView: TextView = findViewById(R.id.textView)
        val buttonPlus:Button = findViewById(R.id.buttonPlus)
        val buttonMinus:Button = findViewById(R.id.buttonMinus)

        val viewModel: MyViewModel = ViewModelProvider(this).get(MyViewModel::class.java)
        viewModel.number.observe(this, Observer { textView.text = it.toString() })


        buttonPlus.setOnClickListener {
            viewModel.modifyNumber(1)
        }

        buttonMinus.setOnClickListener {
            viewModel.modifyNumber(-1)
        }




    }
}